# -*- coding: utf-8 -*-

# Author: Ruymán Reyes Castro
#         Juan José Fumero Alfonso


# Information about GNU extensions
# http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html#C-Extensions

# Informacion about builtins to call other funcionts
# http://gcc.gnu.org/onlinedocs/gcc/Constructing-Calls.html#Constructing-Calls


from yacf.Frontend.C99 import c99_lexer
from ply.lex import TOKEN

class GNULexer(object):

#    reserved = {
#        # GNU
#        '__attribute__'       : 'GNU_ATTRIBUTE',
#        '__restrict__'        : 'GNU_RESTRICT',
#        '__THROW'             : 'GNU_THROW',
#        # Builtings
#        '__builtin_va_list' : 'BUILTIN_VA_LIST',
#        '__builtin_va_arg'  : 'BUILTIN_VA_ARG',
#        '__builtin_offsetof': 'BUILTIN_OFFSETOF',
#        '__builtin_choose_expr': 'BUILTIN_CHOOSE_EXPR',
#        '__builtin_types_compatible_p': 'BUTILTIN_TYPES_COMPATIBLE_P',
#        }
#    allreserved = reserved.copy()
#    allreserved.update(c99_lexer.C99Lexer.keyword_map)
#
#    tokens = list(reserved.values()) + list(c99_lexer.C99Lexer.tokens) + [] 

    @staticmethod
    def get_tokens():
            reserved = {
                # GNU
                '__attribute__'       : 'GNU_ATTRIBUTE',
                '__restrict__'        : 'GNU_RESTRICT',
#                '__THROW'             : 'GNU_THROW',
#                '__inline__'          : 'GNU_INLINE',
                # Builtins
                '__builtin_va_list' : 'BUILTIN_VA_LIST',
                '__builtin_va_arg'  : 'BUILTIN_VA_ARG',
                '__builtin_offsetof': 'BUILTIN_OFFSETOF',
#                '__builtin_choose_expr': 'BUILTIN_CHOOSE_EXPR',
#                '__builtin_types_compatible_p': 'BUTILTIN_TYPES_COMPATIBLE_P',
                }

            tokens = list(reserved.values()) + []
            return tokens
        

    def t_BUILTIN_VA_LIST(self, t):
        r'__builtin_va_list'
        t.type = 'BUILTIN_VA_LIST'
        return t

    def t_GNU_ATTRIBUTE(self, t):
        r'__attribute__'
        t.type = 'GNU_ATTRIBUTE'
        return t

    def t_GNU_RESTRICT(self, t):
        r'__restrict__|__restrict'
        t.type = 'GNU_RESTRICT'
        return t

    @staticmethod
    def get_states():
        states = tuple()
        return states

